/* GUI CONVERTED from rsctmt.p (converter v1.76) Fri Aug 23 22:29:59 2002 */
/* rsctmt.p - Release Management - Container Maintenance                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.7.1.11 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3    LAST MODIFIED: 10/12/92           BY: WUG *G462*          */
/* REVISION: 7.3    LAST MODIFIED: 06/01/93           BY: WUG *GB46*          */
/* REVISION: 7.5    LAST MODIFIED: 11/14/94           BY: mwd *J034*          */
/* REVISION: 7.5    LAST MODIFIED: 12/09/94           BY: taf *J038*          */
/* REVISION: 7.3    LAST MODIFIED: 05/10/95           BY: dxk *G0MC*          */
/* REVISION: 7.3    LAST MODIFIED: 08/04/95           BY: vrn *G0TN*          */
/* REVISION: 8.5    LAST MODIFIED: 03/08/96           BY: vrn *G1NV*          */
/* REVISION: 8.6    LAST MODIFIED: 04/02/97   BY: *K09H* Vinay Nayak-Sujir    */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane            */
/* REVISION: 8.6E   LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton         */
/* REVISION: 8.6E   LAST MODIFIED: 06/11/98   BY: *L020* Charles Yen          */
/* REVISION: 9.0    LAST MODIFIED: 03/29/99   BY: *J3BM* Reetu Kapoor         */
/* REVISION: 9.1    LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates           */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane     */
/* REVISION: 9.1    LAST MODIFIED: 09/05/00   BY: *N0RF* Mark Brown           */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.7.1.8       BY: Kirti Desai        DATE: 05/22/01  ECO: *N0Y4* */
/* Revision: 1.7.1.9       BY: Jean Miller        DATE: 05/15/02  ECO: *P05V* */
/* Revision: 1.7.1.10      BY: Tiziana G.         DATE: 05/24/02  ECO: *P03Z* */
/* $Revision: 1.7.1.11 $      BY: Gnanasekar         DATE: 08/20/02  ECO: *M202* */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "2+ "}

define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
define new shared variable ship_abs_id like abs_mstr.abs_id no-undo.
define new shared variable cont_abs_id like abs_mstr.abs_id no-undo.

define shared variable global_recid as recid.

define variable disp_abs_id like abs_id.
define variable abs_recid as recid.
define variable del-yn like mfc_logical.
define variable deassign like mfc_logical.
define variable old_gwt like pt_net_wt.
define variable old_nwt like pt_net_wt.
define variable old_vol like abs_vol.
define variable diff_gwt like pt_net_wt.
define variable diff_nwt like pt_net_wt.
define variable diff_vol like abs_vol.
define variable wt_conv as decimal.
define variable vol_conv as decimal.
define variable nullstr as character.
define variable ship_db as character.
define variable undo-trans like mfc_logical.
define variable dummy_logi as logical no-undo.
define variable total_received like pod_qty_rcvd no-undo.
define variable base_amt like pod_pur_cost no-undo.
define variable qty_to_rcv as decimal no-undo.
define variable exch_rate like exr_rate no-undo.
define variable exch_rate2 like exr_rate no-undo.
define variable exch_ratetype like exr_ratetype no-undo.
define variable exch_exru_seq like exru_seq no-undo.
define variable warn_substruct as logical no-undo.
define variable mc-error-number like msg_nbr no-undo.

define buffer abs_mstr_cont for abs_mstr.
define buffer abs_mstr_par for abs_mstr.

define new shared temp-table work_sr_wkfl like sr_wkfl.

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/

if is_wiplottrace_enabled() then do:
   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}
end.

{sotmpdef.i new}
{rcwabsdf.i new}


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
abs_mstr.abs_shipfrom colon 20 label "Supplier"
   ad_name               at 45    no-label
   abs_mstr.abs_id       colon 20 label "Container ID" format "x(12)"
   ad_line1              at 45    no-label
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
abs_mstr.abs_shipto colon 20 label "Ship-To"
   si_desc             at 45    no-label
 SKIP(.4)  /*GUI*/
with frame b side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:HIDDEN in frame b = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
abs_mstr.abs_item   colon 20
   pt_desc1            at 45    no-label
   abs_mstr.abs_qty    colon 20 format "->,>>>,>>9.9<<<<<<<<"
                                label "Qty To Receive"
   abs_mstr.abs_site   colon 20
   abs_mstr.abs_loc    colon 20
   loc_desc            at 45    no-label
   abs_mstr.abs_lotser colon 20
   abs_mstr.abs_ref    colon 20
 SKIP(.4)  /*GUI*/
with frame c side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-c-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame c = F-c-title.
 RECT-FRAME-LABEL:HIDDEN in frame c = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame c =
  FRAME c:HEIGHT-PIXELS - RECT-FRAME:Y in frame c - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME c = FRAME c:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

for each t_all_data exclusive-lock:
   delete t_all_data.
end. /* FOR EACH t_all_data */

/* The do block eliminates the ambiguity between abs_mstr and workfile
   work_abs_mstr by scoping the abs_mstr record to the do block. */

do for abs_mstr:

   for first abs_mstr
      fields (abs_dataset abs_id abs_item abs_loc abs_lotser abs_par_id
              abs_qty abs_ref abs_shipfrom abs_shipto abs_shp_date
              abs_site abs_type)
      where recid(abs_mstr) = global_recid
   no-lock: end.

   if available abs_mstr and
      abs_id begins "c" and
      abs_type = "r"
   then do:

      for first ad_mstr
         fields (ad_addr ad_line1 ad_name)
         where ad_addr = abs_shipfrom
      no-lock: end.

      display
         abs_shipfrom
         substring(abs_id,2,50) @ abs_id
         ad_name
         ad_line1
      with frame a.

   end.

   for first poc_ctrl
      fields (poc_tol_cst poc_tol_pct)
   no-lock: end.

   mainloop:
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


      do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

         for each sr_wkfl exclusive-lock where sr_userid = mfguser:
            delete sr_wkfl.
         end.
         {gprun.i ""gplotwdl.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      do transaction with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


         prompt-for
            abs_shipfrom abs_id
         editing:

            global_addr = input abs_shipfrom.

            if frame-field = "abs_shipfrom" then do:
               {mfnp05.i abs_mstr abs_id
                  "abs_id begins ""c"" and abs_type = ""r"" "
                  abs_shipfrom
                  "input abs_shipfrom"}

               if recno <> ? then do:

                  for first ad_mstr
                     fields (ad_addr ad_line1 ad_name)
                     where ad_addr = abs_shipfrom
                  no-lock: end.

                  disp_abs_id = substring(abs_id,2,50).

                  display
                     abs_shipfrom
                     disp_abs_id @ abs_id
                     ad_name  when (available ad_mstr)
                     ""       when (not available ad_mstr) @ ad_name
                     ad_line1 when (available ad_mstr)
                     ""       when (not available ad_mstr) @ ad_line1.
               end.
            end.

            else
            if frame-field = "abs_id" then do:

               {mfnp05.i abs_mstr abs_id
                     "abs_shipfrom = input abs_shipfrom
                      and abs_id begins ""c"" and abs_type = ""r"" "
                      abs_id
                      " ""c"" + input abs_id"}

               if recno <> ? then do:

                  for first ad_mstr
                     fields (ad_addr ad_line1 ad_name)
                     where ad_addr = abs_shipfrom
                  no-lock: end.

                  disp_abs_id = substring(abs_id,2,50).

                  display
                     abs_shipfrom
                     disp_abs_id @ abs_id
                     ad_name  when (available ad_mstr)
                     ""       when (not available ad_mstr) @ ad_name
                     ad_line1 when (available ad_mstr)
                     ""       when (not available ad_mstr) @ ad_line1.
               end.
            end.

            else do:
               status input.
               readkey.
               apply lastkey.
            end.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         for first vd_mstr
            fields (vd_addr)
            where vd_addr = input abs_shipfrom
         no-lock: end.

         if not available vd_mstr then do:
            {pxmsg.i &MSGNUM=2 &ERRORLEVEL=3}
            next-prompt abs_shipfrom.
            undo, retry.
         end.

         for first ad_mstr
            fields (ad_addr ad_line1 ad_name)
            where ad_addr = input abs_shipfrom
         no-lock: end.

         if input abs_id = "" then do:
            {pxmsg.i &MSGNUM=8168 &ERRORLEVEL=3}
            next-prompt abs_id.
            undo, retry.
         end.

      end.

      do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


         find abs_mstr where abs_shipfrom = input frame a abs_shipfrom
            and abs_id = "c" + input frame a abs_id
         exclusive-lock no-error.

         if available abs_mstr and
            abs_type <> "r"
         then do:
            {pxmsg.i &MSGNUM=5813 &ERRORLEVEL=3}
            /* SELECTED CONTAINER HAS INVALID TYPE */
            next-prompt abs_id with frame a.
            undo mainloop, retry mainloop.
         end.

         if not available abs_mstr then do:

            /* Creating new record */
            {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}

            create abs_mstr.
            assign
               abs_shipfrom = input frame a abs_shipfrom
               abs_id       = "c" + input frame a abs_id
               abs_site     = abs_shipto
               abs_type     = "r"
               abs_qty      = 1
               abs_shp_date = today.
         end.

         cont_abs_id = input frame a abs_id.

         for first si_mstr
            fields (si_db si_desc si_site)
            where si_site = abs_shipto
         no-lock: end.
/*GUI*/ if global-beam-me-up then undo, leave.


         clear frame b.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.

         display
            abs_shipto
            si_desc when (available si_mstr)
         with frame b.

         if available si_mstr then do:
            {gprun.i ""gpsiver.p""
               "(input abs_shipto,
                 input recid(si_mstr),
                 output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.
         else do:
            {gprun.i ""gpsiver.p""
               "(input abs_shipto, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

         if return_int = 0 then do:
            {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
            /* USER DOES NOT HAVE ACCESS TO SITE */
            undo mainloop, retry mainloop.
         end.

         do for abs_mstr_par:
            find abs_mstr_par
               where abs_mstr_par.abs_shipfrom = abs_mstr.abs_shipfrom
                 and abs_mstr_par.abs_id = abs_mstr.abs_par_id
            no-lock no-error.
            if available abs_mstr_par then do:
               /* This is subordinate to */
               {pxmsg.i &MSGNUM=8102 &ERRORLEVEL=1 &MSGARG1=abs_id}
            end.
         end.

         /* HANDLE CAN-FIND IDIOSYNCRASY WITH ADD'L CAN-FIND */
         if can-find(first abs_mstr_cont
                     where abs_mstr_cont.abs_shipfrom = abs_mstr.abs_shipfrom
                       and abs_mstr_cont.abs_par_id = abs_mstr.abs_id)
         or can-find(abs_mstr_cont
               where abs_mstr_cont.abs_shipfrom = abs_mstr.abs_shipfrom
                 and abs_mstr_cont.abs_par_id = abs_mstr.abs_id)
         then do:
            /* Contents (container or item) exist */
            {pxmsg.i &MSGNUM=8103 &ERRORLEVEL=1}
         end.
         else do on error undo, retry
                 on endkey undo mainloop, retry mainloop
         with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

            {rsshmta.i}
         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         ststatus = stline[3].
         status input ststatus.

         for first pt_mstr
            fields (pt_desc1 pt_loc pt_part pt_um)
            where pt_part = abs_item
         no-lock: end.

         display
            abs_item
            pt_desc1  when (available pt_mstr)
            abs_qty
            abs_site
            abs_loc
            abs_lotser
         with frame c.

         /* FORCE THE CONTROL TO FALL THROUGH ON ENDKEY (F4), HIDE THE FRAME,
            AND THEN DO THE NORMAL ENDKEY PROCESSING OF DO BLOCK          */
         cont-item-blk:
         do on error  undo, retry
            on endkey undo cont-item-blk, leave cont-item-blk
         with frame c:
/*GUI*/ if global-beam-me-up then undo, leave.


            set abs_item.

            for first pt_mstr
               fields (pt_desc1 pt_loc pt_part pt_um)
               where pt_part = abs_item
            no-lock: end.
/*GUI*/ if global-beam-me-up then undo, leave.


            if not available pt_mstr then do:
               {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
               undo, retry.
            end.

            if new abs_mstr then do:
               assign
                  abs_site = abs_shipto
                  abs_loc = pt_loc.

               display
                  abs_site
                  abs_loc.
            end.

            display pt_desc1.

            global_part = abs_item.

            set
               abs_qty
               abs_site
               abs_loc
               abs_lotser
               abs_ref
            editing:
               assign
                  global_site = input abs_site
                  global_loc = input abs_loc
                  global_lot = input abs_lotser.
               readkey.
               apply lastkey.
            end.

            for first si_mstr
               fields (si_db si_desc si_site)
               where si_site = abs_site
            no-lock: end.

            if not available si_mstr then do:
               {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
               next-prompt abs_site.
               undo, retry.
            end.

            for first loc_mstr
               fields (loc_desc loc_loc loc_site)
               where loc_site = abs_site
               and   loc_loc  = abs_loc
            no-lock: end.

            if not available loc_mstr then do:
               {pxmsg.i &MSGNUM=229 &ERRORLEVEL=3}
               next-prompt abs_loc.
               undo, retry.
            end.

            display
               pt_desc1
               loc_desc.

            {gprun.i ""icedit.p""
               "(""RCT-PO"",
                 abs_site,
                 abs_loc,
                 abs_item,
                 abs_lotser,
                 """",
                 abs_qty,
                 pt_um,
                 """",
                 """",
                 output undo-trans)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            if undo-trans then undo, retry.

            /* If specified site is not defined ship-from site, */
            /* Make sure it's in the same database              */
            if abs_site <> abs_mstr.abs_shipto then do:

               for first si_mstr
                  fields (si_db si_desc si_site)
                  where si_site = abs_mstr.abs_shipto
               no-lock: end.

               ship_db = si_db.

               for first si_mstr
                  fields (si_db si_desc si_site)
                  where si_site = abs_site
               no-lock: end.

               if si_db <> ship_db then do:
                  /* All ship-to sites must be in the same database */
                  {pxmsg.i &MSGNUM=8169 &ERRORLEVEL=3}
                  bell.
                  next-prompt abs_site.
                  undo, retry.
               end.

            end.

         end.  /* cont-item-blk */

         hide frame c no-pause.
         if keyfunction(lastkey) = 'END-ERROR' then
            undo mainloop, retry mainloop.

         abs_recid = recid(abs_mstr).

      end.

      for first abs_mstr
         fields (abs_dataset abs_id abs_item abs_loc abs_lotser abs_par_id
                 abs_qty abs_ref abs_shipfrom abs_shipto abs_shp_date
                 abs_site abs_type)
         where recid(abs_mstr) = abs_recid
      no-lock: end.

      /* MAINTAIN CONTAINERS */
      {gprun.i ""rsshmta.p"" "(input abs_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /* MAINTAIN ITEMS */
      {gprun.i ""rsshmtb.p"" "(input abs_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /* EXPLODE SHIPPER TO GET ORDER DETAIL */
      for each work_abs_mstr exclusive-lock:
         delete work_abs_mstr.
      end.

      {gprun.i ""rcsoisa.p"" "(input recid(abs_mstr))"}
/*GUI*/ if global-beam-me-up then undo, leave.


      warn_substruct = no.

      {rsshmtt.i}

      global_recid = recid(abs_mstr).

   end.

end. /* do for abs_mstr */

if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_funcs no-error.
